<?php

/*
 * Object/PSPlanning.php
 */

namespace RHX\Model\Object;

use Zend\Db\Adapter\Adapter;

class PSPlanning {

    public $periode_id;
    public $periode_libelle;
    public $semaine_id;
    public $semaine_libelle;
    public $lundi;
    public $dimanche;
    public $pp_id;
    public $template;
    public $template_libelle;
    public $site_id;
    public $site_libelle;
    protected $adapter;

    public function __construct(Adapter $adapter, $data = array()) {
	$this->exchangeArray($data);
	$this->adapter = $adapter;
    }

    public function exchangeArray($data) {
	$this->periode_id	 = isset($data['periode_id']) ? $data['periode_id'] : null;
	$this->periode_libelle	 = isset($data['periode_libelle']) ? $data['periode_libelle'] : null;
	$this->semaine_id	 = isset($data['semaine_id']) ? $data['semaine_id'] : null;
	$this->semaine_libelle	 = isset($data['semaine_libelle']) ? $data['semaine_libelle'] : null;
	$this->lundi		 = isset($data['lundi']) ? $data['lundi'] : null;
	$this->dimanche		 = isset($data['dimanche']) ? $data['dimanche'] : null;
	$this->pp_id		 = isset($data['pp_id']) ? $data['pp_id'] : null;
	$this->template		 = isset($data['template']) ? $data['template'] : null;
	$this->template_libelle	 = isset($data['template_libelle']) ? $data['template_libelle'] : null;
	$this->site_id		 = isset($data['site_id']) ? $data['site_id'] : null;
	$this->site_libelle	 = isset($data['site_libelle']) ? $data['site_libelle'] : null;
    }

    public function getArrayCopy() {
	return get_object_vars($this);
    }

    /**
     * Récupérer la Période
     *
     * @return \RHX\Model\Object\Periode
     */
    public function getPeriode() {
	// Table
	$periodeTable	 = new \RHX\Model\Table\PeriodeTable($this->adapter);
	$periode	 = null;
	try {
	    $periode = $periodeTable->get($this->periode_id);
	}
	catch (\Exception $ex) {
	    $periode = new Periode();
	}

	return $periode;
    }

    /**
     * Récupérer la semaine
     *
     * @return \RHX\Model\Object\Semaine
     */
    public function getSemaine() {
	// table
	$semaineTable	 = new \RHX\Model\Table\SemaineTable($this->adapter);
	$semaine	 = null;
	try {
	    $semaine = $semaineTable->get($this->semaine_id);
	}
	catch (\Exception $ex) {
	    $semaine = new Semaine();
	}

	return $semaine;
    }

    /**
     * Récupérer les Infos du Planning Type
     * 
     * @return \RHX\Model\Object\PlanningTemplate
     */
    public function getTemplate() {
	// table
	$templateTable	 = new \RHX\Model\Table\PlanningTemplateTable($this->adapter);
	$template	 = null;
	try {
	    $template = $template->getTemplate($template);
	}
	catch (\Exception $ex) {
	    $template = new PlanningTemplate($this->adapter);
	}

	return $template;
    }
    
    /**
     * Planning Periode
     * 
     * @return PlanningPeriode|null
     */
    public function getPlanningPeriode(){
	$tablePPeriode = new \RHX\Model\Table\PlanningPeriodeTable($this->adapter);
	try{
	    $pPeriode = $tablePPeriode->get($this->pp_id);
	    return $pPeriode;
	}catch(\Exception $ex){
	    return null;
	}
    }

}

?>
